/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package core.util;

import org.apache.log4j.Logger;

/**
 *
 * @author Vincenzo Merlo, Scuderi Giovanni Luca, Paolo Giuffrida
 */
public class IDManager {

    @SuppressWarnings("unused")
	private final Logger logger = COREServiceRegistry.getLogger(IDManager.class.toString());
    private static int lastID = 0;
    private volatile static IDManager instance = null;

    /**
     *
     * @return
     */
    public static IDManager getInstance() {
        // needed because once there is singleton available no need to acquire
        // monitor again & again as it is costly
        if (instance == null) {
            synchronized (IDManager.class) {
                // this is needed if two threads are waiting at the monitor at the
                // time when singleton was getting instantiated
                if (instance == null) {
                    instance = new IDManager();
                }
            }
        }
        return (instance);
    }

    /**
     *
     * @return
     */
    public synchronized int getID() {
        lastID++;
        return lastID;
    }
}
